#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int lengthOfLIS(vector<int>& nums)
    {
        int n = nums.size();
        vector<int> dp(n, 1);
        int ret = 1;
        for (int i = 1; i < n; i++)
        {
            for (int j = 0; j < i; j++)
            {
                if (nums[i] > nums[j]) dp[i] = max(dp[i], dp[j] + 1);
            }

            ret = max(ret, dp[i]);
        }

        return ret;
    }
};

class Solution {
public:
    int maxProduct(vector<int>& nums)
    {
        int ret = 0;
        int n = nums.size();
        vector<int> f(n, 1);
        vector<int> g(n, 1);
        if (nums[0] > 0) f[0] = nums[0];
        else g[0] = nums[0];
        ret = nums[0];
        for (int i = 1; i < n; i++)
        {
            if (nums[i] > 0)
            {
                f[i] = max(nums[i], f[i - 1] * nums[i]);
                g[i] = nums[i] * g[i - 1];
            }
            else
            {
                f[i] = g[i - 1] * nums[i];
                g[i] = min(nums[i], f[i - 1] * nums[i]);
            }
            ret = max(f[i], ret);
        }


        return ret;
    }
};

class Solution {
public:
    bool canPartition(vector<int>& nums)
    {
        int n = nums.size();
        int total = 0;
        for (auto c : nums) total += c;
        if (total % 2 != 0) return false;

        int target = total / 2;
        vector<vector<bool>> dp(n + 1, vector<bool>(target + 1));
        for (int i = 0; i <= n; i++) dp[i][0] = true;

        for (int i = 1; i <= n; i++)
        {
            for (int j = 0; j <= target; j++)
            {
                dp[i][j] = dp[i - 1][j];
                if (j >= nums[i - 1]) dp[i][j] = dp[i][j] || dp[i - 1][j - nums[i - 1]];
            }
        }

        return dp[n][target];
    }
};